package com.xiaocg.momento.black_box;

import com.xiaocg.mediator.Mediator;
import javassist.bytecode.Mnemonic;

public class GameRole {
    private int vit;//生命力
    private int atk;//攻击力
    private int def;//防御力

    public void initState(){
        this.vit = 100;
        this.atk = 100;
        this.def = 100;
    }

    public void fight(){
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }


    private class RoleStateMomento implements Momento{
        private int vit;//生命力
        private int atk;//攻击力
        private int def;//防御力

        public RoleStateMomento(int vit, int atk, int def) {
            this.vit = vit;
            this.atk = atk;
            this.def = def;
        }

        public RoleStateMomento() {
        }

        public int getVit() {
            return vit;
        }

        public void setVit(int vit) {
            this.vit = vit;
        }

        public int getAtk() {
            return atk;
        }

        public void setAtk(int atk) {
            this.atk = atk;
        }

        public int getDef() {
            return def;
        }

        public void setDef(int def) {
            this.def = def;
        }
    }

    /**
     * 保存角色状态
     * @return
     */
    public Momento save(){
        return new RoleStateMomento(vit,atk,def);
    }

    /**
     * 恢复角色状态
     * @return
     */
    public void recoverState(Momento momento1){
        RoleStateMomento momento = (RoleStateMomento)momento1;
        this.vit = momento.getVit();
        this.atk = momento.getAtk();
        this.def = momento.getDef();
    }

    /**
     * 恢复角色状态
     * @return
     */
    public void show(){
        System.out.println("生命力 "+this.vit);
        System.out.println("攻击力 "+this.atk);
        System.out.println("防御力 "+this.def);
    }

    public int getVit() {
        return vit;
    }

    public void setVit(int vit) {
        this.vit = vit;
    }

    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    public int getDef() {
        return def;
    }

    public void setDef(int def) {
        this.def = def;
    }
}
